//
//  FDCaseCell.m
//  FamousDoctorOnline
//
//  Created by 丁鼎 on 16/7/7.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#import "FDCaseCell.h"

@interface FDCaseCell ()

@property (nonatomic,weak) UIImageView *photo;

@property (nonatomic,weak) UILabel *currenttimelabel;

@property (nonatomic,weak) UILabel *diseaselabel;

@property (nonatomic,weak) UILabel *detail;

@property (nonatomic,weak) UILabel *baselabel;

@property (nonatomic,weak) UILabel *titleLabel1;

@property (nonatomic,weak) UILabel *titleLabel2;

@property (nonatomic,weak) UIImageView *leftRound;

@property (nonatomic,weak) UIImageView *leftLine;

@end

@implementation FDCaseCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)setupUI
{
    UILabel *currenttimelabel = [[UILabel alloc]init];
    self.currenttimelabel = currenttimelabel;
    currenttimelabel.textColor = [UIColor lightGrayColor];
    [self addSubview:currenttimelabel];
    
    UIImageView *photo  = [[UIImageView alloc]init];
    self.photo  = photo;
    [self addSubview:photo];
    
    UILabel *diseaseLabel = [[UILabel alloc]init];
    self.diseaselabel = diseaseLabel;
    diseaseLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:diseaseLabel];
    
    UILabel *baselabel = [[UILabel alloc]init];
    self.baselabel = baselabel;
    baselabel.textColor = [UIColor lightGrayColor];
    [self addSubview:baselabel];
    
    UILabel *detail = [[UILabel alloc]init];
    self.detail = detail;
    detail.numberOfLines = 2;
    detail.textColor = [UIColor lightGrayColor];
    [self addSubview:detail];
    
    UILabel *titleLabel1 = [[UILabel alloc]init];
    self.titleLabel1 = titleLabel1;
    titleLabel1.text = @"疾病类型";
    [self addSubview:titleLabel1];
    
    UILabel *titleLabel2 = [[UILabel alloc]init];
    self.titleLabel2 = titleLabel2;
    titleLabel2.text = @"基本类型";
    [self addSubview:titleLabel2];
    
    UIImageView *leftRound =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_rb_img_sel.png"]];
    self.leftRound = leftRound;
    [self  addSubview:leftRound];
    
    UIImageView *liftLine = [[UIImageView alloc]init];
    self.leftLine = liftLine;
    liftLine.backgroundColor = FDColor(49, 199, 198);
    [self addSubview:liftLine];
    
}


-(void)layoutSubviews
{
    [self.leftRound mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.top.mas_equalTo(10);
        make.width.height.mas_equalTo(15);
    }];
    
    [self.leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.leftRound.mas_centerX);
        make.top.equalTo(self.leftRound.mas_bottom);
        make.width.mas_equalTo(2);
        make.height.equalTo(self.mas_height);
    }];
    [self.currenttimelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(30);
    }];
    

    if(self.model.photo)
    {
    [self.photo mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(100);
        make.top.equalTo(self.currenttimelabel.mas_bottom).offset(10);
        make.left.equalTo(self.currenttimelabel.mas_left);
        make.height.mas_equalTo(100);
    }];
    [self.detail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.photo.mas_bottom).offset(5);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];
     
    }
    else{
        [self.photo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.currenttimelabel.mas_bottom).offset(10);
            make.left.equalTo(self.currenttimelabel.mas_left);
            make.height.mas_equalTo(100);
            make.width.mas_equalTo(0);
        }];
        
    [self.detail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.photo.mas_right).offset(5);
        make.top.equalTo(self.baselabel.mas_bottom).offset(10);
        make.right.mas_equalTo(-10);
    }];
    
    }
    
    
    [self.titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.currenttimelabel.mas_bottom).offset(10);
        make.left.equalTo(self.photo.mas_right).offset(5);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(30);
    }];
    
    [self.titleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel1.mas_bottom).offset(10);
        make.left.equalTo(self.titleLabel1.mas_left);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(30);
    }];
    
    [self.diseaselabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel1.mas_top);
        make.left.equalTo(self.titleLabel1.mas_right).offset(10);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(30);
    }];
    
    [self.baselabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel2.mas_top);
        make.left.equalTo(self.diseaselabel.mas_left);
        make.width.equalTo(self.diseaselabel.mas_width);
        make.height.equalTo(self.diseaselabel.mas_height);
    }];

}

-(void)setModel:(FDCaseModel *)model
{
    _model = model;
    
    self.currenttimelabel.text = model.currentTime;
    
    self.diseaselabel.text = model.diseaseKind;
    self.baselabel.text = model.baseKind;
    self.detail.text = model.detail;
    if(model.photo)
    {
    self.photo.image = model.photo;
    }
}



@end
